import axios from "axios";
import { Indicator } from 'mint-ui';
import store from '@/store'
import router from "@/router";

const request = axios.create({
    baseURL: '/api',
    timeout: 50000
})

request.interceptors.request.use(config => {
    Indicator.open();

    if (config.headers.token) {
        config.headers.token = store.state.user.token;
        if (!config.headers.token) {
            router.push('/login')
        }
    }

    return config;
}, error => {
    return Promise.reject(error)
})

request.interceptors.response.use(res => {
    Indicator.close();
    return res.data;
}, error => {
    return Promise.reject(error)
})

export default request;